package com.sgb.trip.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.sgb.trip.R;
import com.sgb.trip.databinding.TripItemPassengerChoosedBinding;
import com.sgb.trip.entity.PassengerInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/6/18
 * Author:黄淋
 * Description:订单页已选择的乘客的adapter
 */
public class PassengerChosenAdapter extends BaseRecycleAdapter<PassengerInfoEntity> {

    public PassengerChosenAdapter(Context context, List<PassengerInfoEntity> datas) {
        super(context, R.layout.trip_item_passenger_choosed, datas);
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    public void convert(ItemViewHolder holder, PassengerInfoEntity entity) {

        TripItemPassengerChoosedBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.tvPassengerName.setText(entity.getName());
        holder.getItem().setSelected(entity.isSelected());

        if (entity.isSelected()) {
            binding.tvPassengerName.setTextColor(context.getResources().getColor(R.color.color_main));
            binding.rlChoose.setBackground(context.getResources().getDrawable(R.drawable.bg_stroke_ef4033_corner5));
            binding.ivChosenPassenger.setVisibility(View.VISIBLE);
        } else {
            binding.tvPassengerName.setTextColor(context.getResources().getColor(R.color.color_333333));
            binding.rlChoose.setBackground(context.getResources().getDrawable(R.drawable.bg_stroke_c0c4cc_corner5));
            binding.ivChosenPassenger.setVisibility(View.GONE);
        }

        if (entity.getName().equals("新增") || entity.getName().equals("更多")) {
            binding.ivAddPassenger.setVisibility(View.VISIBLE);
            binding.tvPassengerName.setTextColor(context.getResources().getColor(R.color.color_5792FD));
            binding.rlChoose.setBackground(context.getResources().getDrawable(R.drawable.bg_stroke_5792fd_corner5));
            binding.ivChosenPassenger.setVisibility(View.GONE);

        } else {
            binding.ivAddPassenger.setVisibility(View.GONE);
        }
    }
}
